Skip to content

handle non-finite bounds in BigIntegerValidator range checks#414

Open
sahvx655-wq wants to merge 1 commit into
apache:masterfrom
sahvx655-wq:bigint-nonfinite-bound
Open

handle non-finite bounds in BigIntegerValidator range checks#414
sahvx655-wq wants to merge 1 commit into
apache:masterfrom
sahvx655-wq:bigint-nonfinite-bound

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

BigIntegerValidator's minValue(Number, Number) and maxValue(Number, Number) compare the operands as BigDecimal, but unlike the equivalent BigDecimalValidator overloads they never guard for a non-finite bound. A Double.NaN, POSITIVE_INFINITY or NEGATIVE_INFINITY argument is routed straight into BigDecimal.valueOf(double), which cannot represent those values and throws NumberFormatException, so the call (and the inherited isInRange that delegates to it) blows up with an undeclared exception rather than returning a boolean. I traced this from an open-ended range check where an infinite upper bound threw instead of accepting every finite value; BigDecimalValidator accepts the same bound without complaint, so the two validators disagree.

The fix guards both overrides with isFinite and falls back to the doubleValue() comparison when either operand is non-finite, mirroring BigDecimalValidator. The finite path is untouched, so the exact-magnitude and fractional-bound behaviour stays as it was; only the previously-throwing case changes, with a NaN bound never satisfied and an infinity treated as an open bound. Keeping the guard in the callee means every entry point stays consistent without callers having to sanitise their bounds first.

@garydgregory

Copy link
Copy Markdown
Member

Please keep track of what is happening to your existing PRs: #410 has been broken for almost a week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants